package br.com.sgmf.dao;

import br.com.sgmf.model.Parte;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

@Repository
public class ParteDAO {

    @PersistenceContext
    private EntityManager manager;

    @Transactional
    public void save(Parte parte) {
        manager.persist(parte);
    }

    @Transactional
    public void update(Parte parte) {
        manager.merge(parte);
    }

    @Transactional
    public void delete(Parte parte) {
        manager.remove(parte);
    }

    public Parte findById(Integer id) {
        return manager.find(Parte.class, id);
    }

    @SuppressWarnings("unchecked")
    public List<Parte> findAll() {
        return manager.createQuery("SELECT p FROM Parte p").getResultList();
    }

}
